<template>
    <div id="comic_diversity">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/novel_list' }">小说列表</el-breadcrumb-item>
            <el-breadcrumb-item>小说章节</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card class="box-card">
            <el-form ref="form" label-width="80px" :inline="true" size="small">
                <el-form-item>
                    <el-button type="primary" size="small" @click="add">添加</el-button>
                </el-form-item>
            </el-form>
            <el-table
                    :data="tableData"
                    border
                    style="width: 100%">
                <el-table-column
                        prop="index"
                        label="序号">
                    <template slot-scope="scope">
                        {{scope.$index+1}}
                    </template>
                </el-table-column>
              <el-table-column
                  prop="chaps"
                  label="第几章节">
              </el-table-column>
                <el-table-column
                        prop="title"
                        label="章节名称">
                </el-table-column>
              <el-table-column
                  prop="submit_at"
                  label="提交时间">
              </el-table-column>
                <el-table-column
                        prop="address"
                        label="审核状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.status==''">已发布</span>
                        <span v-if="scope.row.status=='draft'">草稿</span>
                        <span v-if="scope.row.status=='auditing'">审核中...</span>
                        <span v-if="scope.row.status=='failed'">审核不通过</span>
                        <span  v-if="scope.row.status=='pushing'">定时发布中...</span>

                    </template>
                </el-table-column>
                <el-table-column
                        prop="address"
                        label="操作"
                        width="300">
                    <template slot-scope="scope">
                        <p style="text-align: center">
                            <el-button type="success" plain @click="onPush(scope.row.id)" size="small" v-if="scope.row.review_status==-1">发布</el-button>
                          <el-button type="primary" plain size="small" @click="browsenote(scope.row.chaps)">查看记录</el-button>
                            <el-button type="primary" plain size="small" @click="edit(scope.row.chaps)"  v-if="scope.row.status!='auditing'" >编辑</el-button>
                          <el-button type="text" plain size="small"  v-if="scope.row.status=='auditing'">审核中，不可修改</el-button>
                        </p>
                    </template>
                </el-table-column>
            </el-table>
            <div class="el-pagination">
                <el-pagination
                        background
                        @size-change="changeSize"
                        @current-change="changeCurrent"
                        :current-page="params.pagenum"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="params.pagesize"
                        :layout="this.$store.state.paginationLayout"
                        :total="params.totals">
                </el-pagination>
            </div>
        </el-card>

      <el-dialog :title="formTitle2" :width="this.$store.state.dialogWidth" :visible.sync="browsevisible">

        <el-table
            :data="tableData_sh"
            border
            style="width: 100%">
          <el-table-column
              prop="chaps"
              label="第几章节">
          </el-table-column>
          <el-table-column
              prop="title"
              label="章节名称">
          </el-table-column>
          <el-table-column
              prop="word_count"
              label="章节字数">
          </el-table-column>

          <el-table-column
              prop="submit_at"
              label="审核时间">
            <template slot-scope="scope">
              {{ scope.row.submit_at}}
            </template>
          </el-table-column>

        </el-table>


        <span slot="footer" class="dialog-footer">
            <el-button @click="browsevisible = false" size="small">取 消</el-button>
        </span>
      </el-dialog>
    </div>
</template>

<script>
import {formatDate, isRealNum, uploadimg} from "../../utils/common";
  import quillConfigText from '../../utils/quill-text-config'

  export default {
    name: "comic_diversity",
    data() {
      return {
        params: {
          pagenum: 1,
          pagesize: 10,
          totals: 0
        },
        tableData: [],
        fromTitle: '',
        visible: false,
        anid: '',//小说id
        id: '',//分集id
        editorOption: quillConfigText,
        formTitle: '',
        formTitle2:'',
        browsevisible: false,
        tableData_sh: '',

      }
    },
    created() {
      this.anid = this.$route.query.id;
      this.getList()
    },
    methods: {
      formatDate,

      getList() {
        let data = {
          anid: this.anid,
          page: this.params.pagenum,
          page_size: this.params.pagesize,
        };
        this.$axios.post("writer/chapter/index", data).then((res) => {
          this.params.totals = res.data.count;
          this.tableData = res.data.list;

        });
      },
      // 每页显示多少条
      changeSize(val) {
        this.params.pagesize = val;
        this.getList()
      },
      // 当前显示的页数
      changeCurrent(val) {
        this.params.pagenum = val;
        this.getList()
      },
      add() {
        this.$router.push({
          path: '/novel_chapters',
          query: {
            anid: this.anid
          }
        })
      },
      edit(id) {
        this.id = id;
        this.$router.push({
          path: '/novel_chapters',
          query: {
            id: this.id,
            anid: this.anid
          }
        })
      },
      onPush(id) {
        this.$confirm('确认要提交审核吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post("writer/chapter/push", {id: id}).then((res) => {
            this.$message.success('发布成功');
            this.getList();
          });
        })
      },
      remove(id) {
        this.$confirm('确定要进行操作, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.del('writer/chapter/' + id, '').then((res) => {
            this.$message.success('删除成功!');
            this.getList();
          });
        })
      },
      browsenote(chaps) {

        this.formTitle2 = '浏览编辑记录';

        let data = {
          anid: this.anid,
          index: chaps,
          page: 1,
          page_size: 100,
        };
        this.$axios.post("writer/chapter/browse_auditnote", data).then((res) => {

          this.tableData_sh = res.data;

        });

        this.browsevisible = true;
      },
    }
  }
</script>

<style scoped>
</style>